﻿Imports NMock2

Imports System.Collections.Generic
Imports Microsoft.VisualStudio.TestTools.UnitTesting

Imports Meiners.Libs.Withings
Imports Meiners.Libs.Withings.Core

Namespace Core

    '''<summary>
    '''This is a test class for WBSAPIConnectorTest and is intended
    '''to contain all WBSAPIConnectorTest Unit Tests
    '''</summary>
    <TestClass()> _
    Public Class WBSAPIConnectorTest

        Private testContextInstance As TestContext

        '''<summary>
        '''Gets or sets the test context which provides
        '''information about and functionality for the current test run.
        '''</summary>
        Public Property TestContext() As TestContext
            Get
                Return testContextInstance
            End Get
            Set(ByVal value As TestContext)
                testContextInstance = value
            End Set
        End Property


        ''' <summary>
        ''' Checks if the Method adds a slash, when its missing in WSBAPI URL
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod(), _
        ExpectedException(GetType(System.ArgumentNullException), "serviceName")> _
        Public Sub BuildWSBAPIAddress_Error_Parameter1()

            Dim target As WBSAPIConnector_Accessor = New WBSAPIConnector_Accessor
            Dim serviceName As String = Nothing
            Dim action As String = "action"
            Dim parameter As New Dictionary(Of String, String)

            target.BuildWSBAPIAddress(serviceName, action, parameter)
        End Sub
        ''' <summary>
        ''' Checks if the Method adds a slash, when its missing in WSBAPI URL
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod(), _
        ExpectedException(GetType(System.ArgumentNullException), "action")> _
        Public Sub BuildWSBAPIAddress_Error_Parameter2()

            Dim target As WBSAPIConnector_Accessor = New WBSAPIConnector_Accessor
            Dim serviceName As String = "serviceName"
            Dim action As String = Nothing
            Dim parameter As New Dictionary(Of String, String)

            target.BuildWSBAPIAddress(serviceName, action, parameter)
        End Sub
        ''' <summary>
        ''' Checks if the Method adds a slash, when its missing in WSBAPI URL
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod()> _
        Public Sub BuildWSBAPIAddress_AddingSlash()

            Dim target As WBSAPIConnector_Accessor = New WBSAPIConnector_Accessor
            Dim serviceName As String = "asdf"
            Dim action As String = "wertz"
            Dim parameter As New Dictionary(Of String, String)
            Dim actual As String
            Dim expected As String = "http://wbsapi.withings.net/asdf?action=wertz"

            target.WSBAPIAddress = "http://wbsapi.withings.net"
            actual = target.BuildWSBAPIAddress(serviceName, action, parameter)

            Assert.AreEqual(Of String)(expected, actual)
        End Sub
        ''' <summary>
        ''' Checks if the Method adds serviceName and ActionName correct
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod()> _
        Public Sub BuildWSBAPIAddress_AcceptsServiceAndActionName()

            Dim target As WBSAPIConnector_Accessor = New WBSAPIConnector_Accessor
            Dim serviceName As String = Guid.NewGuid.ToString
            Dim action As String = Guid.NewGuid.ToString
            Dim parameter As New Dictionary(Of String, String)
            Dim actual As String
            Dim expected As String = String.Format("http://wbsapi.withings.net/{0}?action={1}", serviceName, action)

            actual = target.BuildWSBAPIAddress(serviceName, action, parameter)

            Assert.AreEqual(Of String)(expected, actual)
        End Sub
        ''' <summary>
        ''' Checks if the Method adds serviceName and ActionName correct
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod()> _
        Public Sub BuildWSBAPIAddress_NoParameterNoAmplify()

            Dim target As WBSAPIConnector_Accessor = New WBSAPIConnector_Accessor
            Dim serviceName As String = Guid.NewGuid.ToString
            Dim action As String = Guid.NewGuid.ToString
            Dim parameter As New Dictionary(Of String, String)
            Dim actual As String
            Dim expected As String = String.Format("http://wbsapi.withings.net/{0}?action={1}", serviceName, action)

            Assert.AreEqual(Of Integer)(0, parameter.Count, "Vorraussetzung: Keine Parameter")
            actual = target.BuildWSBAPIAddress(serviceName, action, parameter)

            Assert.IsFalse(actual.Contains("&"), "Should not contains amplify if you have no parameters")
        End Sub
        ''' <summary>
        ''' Checks if the Method adds serviceName and ActionName correct
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod()> _
        Public Sub BuildWSBAPIAddress_Parameter()

            Dim target As WBSAPIConnector_Accessor = New WBSAPIConnector_Accessor
            Dim serviceName As String = Guid.NewGuid.ToString
            Dim action As String = Guid.NewGuid.ToString
            Dim parameter As New Dictionary(Of String, String)
            Dim actual As String
            Dim expected As String = String.Format("http://wbsapi.withings.net/{0}?action={1}&userid=12345", serviceName, action)

            parameter.Add("userid", "12345")
            actual = target.BuildWSBAPIAddress(serviceName, action, parameter)

            Assert.AreEqual(Of String)(expected, actual)
        End Sub

        ''' <summary>
        ''' Checks if the Method adds serviceName and ActionName correct
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod()> _
        Public Sub CheckWebserviceConnection_Success()
            Dim target As WBSAPIConnector_Accessor = New WBSAPIConnector_Accessor
            Dim expected As Boolean = True
            Dim actual As Boolean
            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.probe_SampleResult))
            WBSAPIConnector.WebConnector = webMock
            actual = target.CheckWebserviceConnection()

            Assert.AreEqual(expected, actual)
        End Sub
        ''' <summary>
        ''' Checks if the Method adds serviceName and ActionName correct
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod()> _
        Public Sub CheckWebserviceConnection_Error()
            Dim target As WBSAPIConnector_Accessor = New WBSAPIConnector_Accessor
            Dim expected As Boolean = False
            Dim actual As Boolean
            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value("{""status"":1}"))
            WBSAPIConnector.WebConnector = webMock
            actual = target.CheckWebserviceConnection()

            Assert.AreEqual(expected, actual)
        End Sub


        ''' <summary>
        ''' Checks Parameter validation 
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod(), _
        ExpectedException(GetType(System.ArgumentNullException), "emailAddress")> _
        Public Sub GetAccountUsers_Parameter1()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            target.GetAccountUsers(Nothing, Guid.NewGuid.ToString)
        End Sub
        ''' <summary>
        ''' Checks Parameter validation 
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod(), _
        ExpectedException(GetType(System.ArgumentNullException), "hash")> _
        Public Sub GetAccountUsers_Parameter2()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            target.GetAccountUsers("user@example.com", Nothing)
        End Sub
        ''' <summary>
        ''' Checks if the Method adds serviceName and ActionName correct
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod()> _
        Public Sub GetAccountUsers_Success()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim expected As Boolean = True
            Dim actual As GetUserListResponse
            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.getUserList_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.GetAccountUsers("user@sample.com", Guid.NewGuid.ToString)

            Assert.IsTrue(actual.Users.Count = 3, "3 User hätten in dem Account sein sollen")


            'Hier alle eigenschaften auseinander nehmen
            '-die hinhalten haben hochzeichen
            Dim testWithingsUser As User

            testWithingsUser = (From x As User In actual.Users _
                                Where x.PublicKey = "3753a06f1c5ee6a0").First

            Assert.AreEqual(Of String)("3753a06f1c5ee6a0", testWithingsUser.PublicKey)
            Assert.AreEqual(Of String)("John", testWithingsUser.FirstName)
            Assert.AreEqual(Of String)("Doe", testWithingsUser.LastName)
            Assert.AreEqual(Of String)("JON", testWithingsUser.ShortName)
            Assert.AreEqual(Of GenderEnum)(GenderEnum.Male, testWithingsUser.Gender)
            Assert.AreEqual(Of String)("0", testWithingsUser.FatMethod)
            Assert.IsTrue(testWithingsUser.IsBodyScaleDataPublic)
            Assert.AreEqual(Of Date)(New Date(1970, 1, 1, 0, 0, 0).AddSeconds(211629600), testWithingsUser.Birthdate)



            Assert.IsTrue((From x As User In actual.Users _
                           Where x.PublicKey = "3e203cb659c03995").Count = 1, "SampleUser Jane Doe not found")
            Assert.IsTrue((From x As User In actual.Users _
                           Where x.PublicKey = "051fc9bb6fa571a9").Count = 1, "SampleUser Natalie Doe not found")


        End Sub

        ''' <summary>
        ''' Proofes that the Mothond can handle a incorrect hash
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod()> _
        Public Sub GetAccountUsers_UnkownHash_Error_100()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_100_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            Dim actual As GetUserListResponse
            actual = target.GetAccountUsers("user@sample.com", Guid.NewGuid.ToString)
            Assert.IsInstanceOfType(actual, GetType(GetUserListResponse), "instance is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.HashMissingOrInvalid, actual.Status, "Status is not correct")
            Assert.IsTrue(actual.Users.Count = 0, "User Count should be zero")

        End Sub
        ''' <summary>
        ''' Proofes that the Mothond can handle a incorrect emailadddess
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod()> _
        Public Sub GetAccountUsers_UnkownHash_Error_264()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_264_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            Dim actual As GetUserListResponse
            actual = target.GetAccountUsers("user@sample.com", Guid.NewGuid.ToString)
            Assert.IsInstanceOfType(actual, GetType(GetUserListResponse), "instance is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.EmailAddressIsUnknownInvalid, actual.Status, "Status is not correct")
            Assert.IsTrue(actual.Users.Count = 0, "User Count should be zero")
        End Sub
        ''' <summary>
        ''' Proofes that the Mothond can handle unkown service exceptions
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod()> _
        Public Sub LoadUsers_UnkownHash_Error_2555()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_2555_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            Dim actual As GetUserListResponse
            actual = target.GetAccountUsers("user@sample.com", Guid.NewGuid.ToString)
            Assert.IsInstanceOfType(actual, GetType(GetUserListResponse), "instance is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.AnUnknownErrorOccured, actual.Status, "Status is not correct")
            Assert.IsTrue(actual.Users.Count = 0, "User Count should be zero")

        End Sub




        ''' <summary>
        ''' Checks if the Method adds serviceName and ActionName correct
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod()> _
        Public Sub GetMagicStringForHash_Success()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim expected As String = "4a8947d9-25e849fd"
            Dim actual As String
            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.getMagicString_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.GetMagicStringForHash()

            Assert.AreEqual(Of String)(expected, actual)

        End Sub
        ''' <summary>
        ''' Checks if the Method adds serviceName and ActionName correct
        ''' </summary>
        ''' <remarks></remarks>
        <TestMethod()> _
        Public Sub GetMagicStringForHash_Error()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.getMagicString_Error_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            Try
                target.GetMagicStringForHash()
                Assert.Fail("Exception was not thrown")
            Catch ex As Exception
            End Try


        End Sub



        '''<summary>
        '''Check reaction on Error 247 result
        '''</summary>
        <TestMethod()> _
        Public Sub GetUserTest_Suceess()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = "3753a06f1c5ee6a0"
            Dim actual As GetUserByIDResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.getUserByID_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.GetUser(userID, publicKey)

            Assert.AreEqual(Of String)("3753a06f1c5ee6a0", actual.User.PublicKey)
            Assert.AreEqual(Of String)("John", actual.User.FirstName)
            Assert.AreEqual(Of String)("Doe", actual.User.LastName)
            Assert.AreEqual(Of String)("JON", actual.User.ShortName)
            Assert.AreEqual(Of GenderEnum)(GenderEnum.Male, actual.User.Gender)
            Assert.AreEqual(Of String)("0", actual.User.FatMethod)
            Assert.IsTrue(actual.User.IsBodyScaleDataPublic)
            Assert.AreEqual(Of Date)(New Date(1970, 1, 1, 0, 0, 0).AddSeconds(211629600), actual.User.Birthdate)

        End Sub
        '''<summary>
        '''Check reaction on Error 247 result
        '''</summary>
        <TestMethod(), _
        ExpectedException(GetType(ArgumentNullException))> _
        Public Sub GetUserTest_Fail_Parameter_1()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = -1
            Dim publicKey As String = Guid.NewGuid.ToString

            target.GetUser(userID, publicKey)
        End Sub
        '''<summary>
        '''Check reaction on Error 247 result
        '''</summary>
        <TestMethod(), _
        ExpectedException(GetType(ArgumentNullException))> _
        Public Sub GetUserTest_Fail_Parameter_2()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Nothing

            target.GetUser(userID, publicKey)
        End Sub
        '''<summary>
        '''Check reaction on Error 247 result
        '''</summary>
        <TestMethod()> _
        Public Sub GetUserTest_Fail_Error_247()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_247_SampleResult))
            WBSAPIConnector.WebConnector = webMock


            Assert.IsNull(target.GetUser(userID, publicKey).User)
        End Sub
        '''<summary>
        '''Check reaction on Error 250 result
        '''</summary>
        <TestMethod()> _
        Public Sub GetUserTest_Fail_Error_250()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_250_SampleResult))
            WBSAPIConnector.WebConnector = webMock
       
            Assert.IsNull(target.GetUser(userID, publicKey).User)
        End Sub
        '''<summary>
        '''Check reaction on Error 2555 result
        '''</summary>
        <TestMethod()> _
        Public Sub GetUserTest_Fail_Error_2555()
            Dim target As WBSAPIConnector = New WBSAPIConnector()
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing 
            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_2555_SampleResult))
            WBSAPIConnector.WebConnector = webMock


            Assert.IsNull(target.GetUser(userID, publicKey).User)
        End Sub


        '''<summary>
        '''A test for UpdateUser to check the reaction on missing parameter
        '''</summary>
        <TestMethod()> _
        Public Sub UpdateUserTest_Success()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = "b71d95d5fb963458"
            Dim isPublic As Integer = 1
            Dim expected As Boolean = True
            Dim actual As Boolean

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.probe_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.UpdateUser(userID, publicKey, isPublic).Success
            Assert.AreEqual(Of Boolean)(expected, actual)

        End Sub
        '''<summary>
        '''A test for UpdateUser to check the reaction on missing parameter
        '''</summary>
        <TestMethod()> _
        Public Sub UpdateUserTest_Fail_Error_2555()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString
            Dim isPublic As Integer = 1
            Dim actual As UpdateUserResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_2555_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.UpdateUser(userID, publicKey, isPublic)

            Assert.IsInstanceOfType(actual, GetType(UpdateUserResponse), "Instance is not correct")
            Assert.IsFalse(actual.Success, "Success property is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.AnUnknownErrorOccured, actual.Status, "Status should be 2555")


        End Sub
        '''<summary>
        '''A test for UpdateUser to check the reaction on missing parameter
        '''</summary>
        <TestMethod()> _
        Public Sub UpdateUserTest_Fail_Error_250()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString
            Dim isPublic As Integer = 1
            Dim actual As UpdateUserResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_250_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.UpdateUser(userID, publicKey, isPublic)

            Assert.IsInstanceOfType(actual, GetType(UpdateUserResponse), "Instance is not correct")
            Assert.IsFalse(actual.Success, "Success property is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.UserDataIsNotPublic, actual.Status, "Status should be 250")


        End Sub
        '''<summary>
        '''A test for UpdateUser to check the reaction on missing parameter
        '''</summary>
        <TestMethod()> _
        Public Sub UpdateUserTest_Fail_Error_247()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString
            Dim isPublic As Integer = 1
            Dim actual As UpdateUserResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(Libs.Withings.Core.IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_247_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.UpdateUser(userID, publicKey, isPublic)

            Assert.IsInstanceOfType(actual, GetType(UpdateUserResponse), "Instance is not correct")
            Assert.IsFalse(actual.Success, "Success property is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.UserIdAbsentOrIncorrect, actual.Status, "Status should be 247")

        End Sub
        '''<summary>
        '''A test for UpdateUser to check the reaction on missing parameter
        '''</summary>
        <TestMethod(), _
        ExpectedException(GetType(System.ArgumentNullException))> _
        Public Sub UpdateUserTest_Fail_Parameter_1()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = -1
            Dim publicKey As String = Guid.NewGuid.ToString
            Dim isPublic As Integer = 1
            target.UpdateUser(userID, publicKey, isPublic)

            Assert.Fail("This line should not be reached")
        End Sub
        '''<summary>
        '''A test for UpdateUser to check the reaction on missing parameter
        '''</summary>
        <TestMethod(), _
        ExpectedException(GetType(System.ArgumentNullException))> _
        Public Sub UpdateUserTest_Fail_Parameter_2()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Nothing
            Dim isPublic As Integer = 1
            target.UpdateUser(userID, publicKey, isPublic)

            Assert.Fail("This line should not be reached")
        End Sub
        '''<summary>
        '''A test for UpdateUser to check the reaction on missing parameter
        '''</summary>
        <TestMethod(), _
        ExpectedException(GetType(System.ArgumentNullException))> _
        Public Sub UpdateUserTest_Fail_Parameter_3()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString
            Dim isPublic As Integer = -1
            target.UpdateUser(userID, publicKey, isPublic)

            Assert.Fail("This line should not be reached")
        End Sub



        'Ausrufe prüfen, und schauen ob die parameter stimmen? Oder ist das URL Creatoer test?

        '''<summary>
        '''A test for GetMeasures
        '''</summary>
        <TestMethod()> _
        Public Sub GetMeasuresTest_Success()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = "b71d95d5fb963458"
            Dim actual As GetMeasuresResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").With(New String() {"http://wbsapi.withings.net/measure?action=getmeas&userid=29&publickey=b71d95d5fb963458"}).Will([Return].Value(My.Resources.getMeasures_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.GetMeasures(userID, publicKey)
            Assert.AreEqual(Of DateTime)(Helper.EPOCHToDateTime(1249409679), actual.UpdateTime)
            Assert.IsTrue(actual.ReadMeasureGroups.Count = 2, "MeasureGroups.Count is wrong")

            Dim selection As Collections.Generic.IEnumerable(Of Measure) = Nothing

            Assert.IsTrue(actual.ReadMeasureGroups(0).GetMeasures.Count = 4, "First MeasureCount is wrong")
            Assert.IsTrue(actual.ReadMeasureGroups(1).GetMeasures.Count = 1, "Second MeasureCount is wrong")


            Assert.AreEqual(Of Integer)(2909, actual.ReadMeasureGroups(0).GroupId)
            Assert.AreEqual(Of CategoryEnum)(CategoryEnum.IsMeasure, actual.ReadMeasureGroups(0).Category)
            Assert.AreEqual(Of DateTime)(Helper.EPOCHToDateTime(1222930968), actual.ReadMeasureGroups(0).MeasureGroupDate)
            Assert.AreEqual(Of AttributionStatusEnum)(AttributionStatusEnum.CapturedByDeviceBelongsToUser, actual.ReadMeasureGroups(0).AttributionStatus)
            Assert.AreEqual(Of MeasureTypeEnum)(MeasureTypeEnum.Heigth, actual.ReadMeasureGroups(1).GetMeasures(0).MeasureType)


        End Sub

        '''<summary>
        '''A test for GetMeasures
        '''</summary>
        <TestMethod()> _
        Public Sub GetMeasuresTest_CheckURL()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = "b71d95d5fb963458"


            Dim startDateOriginal As DateTime = New DateTime(2001, 3, 1)
            Dim endDateOriginal As DateTime = New DateTime(2010, 3, 1)
            Dim startDate As Integer = startDateOriginal.Subtract(New DateTime(1970, 1, 1, 0, 0, 0)).Seconds
            Dim endDate As Integer = endDateOriginal.Subtract(New DateTime(1970, 1, 1, 0, 0, 0)).Seconds
            Dim devtype As Integer = CInt(DeviceTypeEnum.BodyScale)
            Dim meastype As Integer = CInt(MeasureTypeEnum.Weight)
            Dim lastUpdateOriginal As DateTime = New DateTime(2010, 1, 1)
            Dim lastUpdate As Integer = lastUpdateOriginal.Subtract(New DateTime(1970, 1, 1, 0, 0, 0)).Seconds
            Dim category As Integer = CInt(CategoryEnum.IsMeasure)
            Dim limit As Integer = 10
            Dim offset As Integer = 0

            Dim expectedURLBase As String = "http://wbsapi.withings.net/measure?action=getmeas"
            Dim expectedURL As String = String.Empty

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)
            WBSAPIConnector.WebConnector = webMock

            expectedURL = expectedURLBase
            expectedURL += String.Format("&userid={0}", userID)
            expectedURL += String.Format("&publickey={0}", publicKey)
            expectedURL += String.Format("&startdate={0}", startDate)
            expectedURL += String.Format("&enddate={0}", endDate)
            expectedURL += String.Format("&devtype={0}", devtype)
            expectedURL += String.Format("&meastype={0}", meastype)
            expectedURL += String.Format("&lastupdate={0}", lastUpdate)
            expectedURL += String.Format("&category={0}", category)
            expectedURL += String.Format("&limit={0}", limit)
            expectedURL += String.Format("&offset={0}", offset)

            Expect.Once.On(webMock).Method("GetWebserviceResponse").With(New String() {expectedURL}).Will([Return].Value(My.Resources.getMeasures_SampleResult))
            target.GetMeasures(userID, publicKey, startDate, endDate, devtype, meastype, lastUpdate, category, limit, offset)

            mocks.VerifyAllExpectationsHaveBeenMet()
        End Sub
        '''<summary>
        '''A test for GetMeasures
        '''</summary>
        <TestMethod(), _
        ExpectedException(GetType(System.ArgumentNullException))> _
        Public Sub GetMeasuresTest_Fail_Parameter_1()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = -1
            Dim publicKey As String = Guid.NewGuid.ToString
            target.GetMeasures(userID, publicKey)

            Assert.Fail("This line should not be reached")
        End Sub
        '''<summary>
        '''A test for GetMeasures
        '''</summary>
        <TestMethod(), _
        ExpectedException(GetType(System.ArgumentNullException))> _
        Public Sub GetMeasuresTest_Fail_Parameter_2()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Nothing
            target.GetMeasures(userID, publicKey)

            Assert.Fail("This line should not be reached")
        End Sub
        '''<summary>
        '''A test for GetMeasures
        '''</summary>
        <TestMethod()> _
        Public Sub GetMeasuresTest_Fail_Status_2555()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            Dim actual As GetMeasuresResponse

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_2555_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.GetMeasures(userID, publicKey)
            Assert.IsInstanceOfType(actual, GetType(GetMeasuresResponse), "instance is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.AnUnknownErrorOccured, actual.Status, "Status is not correct")
            Assert.IsTrue(actual.ReadMeasureGroups.Count = 0, "MeasureGroups Count should be zero")

        End Sub
        '''<summary>
        '''A test for GetMeasures
        '''</summary>
        <TestMethod()> _
        Public Sub GetMeasuresTest_Fail_Status_247()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing
            Dim actual As GetMeasuresResponse

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_247_SampleResult))
            WBSAPIConnector.WebConnector = webMock


            actual = target.GetMeasures(userID, publicKey)
            Assert.IsInstanceOfType(actual, GetType(GetMeasuresResponse), "instance is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.UserIdAbsentOrIncorrect, actual.Status, "Status is not correct")
            Assert.IsTrue(actual.ReadMeasureGroups.Count = 0, "MeasureGroups Count should be zero")

        End Sub
        '''<summary>
        '''A test for GetMeasures
        '''</summary>
        <TestMethod()> _
        Public Sub GetMeasuresTest_Fail_Status_250()
            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString
            Dim actual As GetMeasuresResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_250_SampleResult))
            WBSAPIConnector.WebConnector = webMock


            actual = target.GetMeasures(userID, publicKey)
            Assert.IsInstanceOfType(actual, GetType(GetMeasuresResponse), "instance is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.UserDataIsNotPublic, actual.Status, "Status is not correct")
            Assert.IsTrue(actual.ReadMeasureGroups.Count = 0, "MeasureGroups Count should be zero")

        End Sub


        <TestMethod()> _
        Public Sub ReadSubscription_Success()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = "b71d95d5fb963458"
            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale

            Dim actual As ReadSubscriptionResponse


            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            'Alle paramteter sollten anständig übergeben werden

            Expect.Once.On(webMock).Method("GetWebserviceResponse").With(New String() {"http://wbsapi.withings.net/notify?action=get&userid=29&publickey=b71d95d5fb963458&callbackurl=http%3a%2f%2fwww.yourdomain.net%2fyourCustomApplication.php&appli=1"}).Will([Return].Value(My.Resources.getNotiy_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.ReadSubscription(userID, publicKey, callbackURL, application)
            mocks.VerifyAllExpectationsHaveBeenMet()

            Assert.IsInstanceOfType(actual, GetType(ReadSubscriptionResponse), "instance type is not correct")
            Assert.AreEqual(Of DateTime)(Helper.EPOCHToDateTime(2147483647), actual.ExpireDate, "ExpireDate is not correct")
            Assert.AreEqual(Of String)("Your Own Application Description", actual.Comment, "Comment property is not correct")

        End Sub
        <TestMethod()> _
        Public Sub ReadSubscription_Fail_Parameter()

            Dim target As WBSAPIConnector = New WBSAPIConnector

            'Assertation 1: Exception On Parameter UserID
            Try
                target.ReadSubscription(-1, Guid.NewGuid.ToString, "http://www.yourdomain.net/yourCustomApplication.php", _
                                        DeviceTypeEnum.BodyScale)
                Assert.Fail("ArgumentNullException for Parameter userId was not thrown")
            Catch ex As System.ArgumentNullException
                Assert.AreEqual(Of String)("userID", ex.ParamName, "User ID was not detected")
            Catch ex As Exception
                Assert.Fail("Wrong exception type was thrown on UserID check")
            End Try



            'Assertation 2: Exception On Parameter publicKey
            Try
                target.ReadSubscription(29, Nothing, "http://www.yourdomain.net/yourCustomApplication.php", _
                                         DeviceTypeEnum.BodyScale)
                Assert.Fail("ArgumentNullException for Parameter publicKey was not thrown")
            Catch ex As System.ArgumentNullException
                Assert.AreEqual(Of String)("publicKey", ex.ParamName, "publicKey was not detected")
            Catch ex As Exception
                Assert.Fail("Wrong exception type was thrown on publicKey check")
            End Try

            'Assertation 3: Exception On Parameter callbackURL
            Try
                target.ReadSubscription(29, Guid.NewGuid.ToString, Nothing, _
                                           DeviceTypeEnum.BodyScale)
                Assert.Fail("ArgumentNullException for Parameter callbackURL was not thrown")
            Catch ex As System.ArgumentNullException
                Assert.AreEqual(Of String)("callbackURL", ex.ParamName, "callbackURL was not detected")
            Catch ex As Exception
                Assert.Fail("Wrong exception type was thrown on callbackURL check")
            End Try

            Dim callbackURL As String = String.Empty
            For i As Integer = 0 To 135
                callbackURL += "a"
            Next

            'Assertation 4: Exception On Parameter callbackURL - maxLength
            Try
                target.ReadSubscription(29, Guid.NewGuid.ToString, callbackURL, _
                                           DeviceTypeEnum.BodyScale)
                Assert.Fail("ArgumentException for Parameter callbackURL was not thrown")
            Catch ex As System.ArgumentException
                Assert.AreEqual(Of String)("callbackURL", ex.ParamName, "callbackURL to long problem was not detected")
            Catch ex As Exception
                Assert.Fail("Wrong exception type was thrown on callbackURL-maxlength check")
            End Try

        End Sub
        <TestMethod()> _
        Public Sub ReadSubscription_Fail_Error_247()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = "b71d95d5fb963458"
            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale

            Dim actual As ReadSubscriptionResponse


            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            'Alle paramteter sollten anständig übergeben werden

            Expect.Once.On(webMock).Method("GetWebserviceResponse").With(New String() {"http://wbsapi.withings.net/notify?action=get&userid=29&publickey=b71d95d5fb963458&callbackurl=http%3a%2f%2fwww.yourdomain.net%2fyourCustomApplication.php&appli=1"}).Will( _
                                   [Return].Value(My.Resources.Error_247_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.ReadSubscription(userID, publicKey, callbackURL, application)
            mocks.VerifyAllExpectationsHaveBeenMet()

            Assert.IsInstanceOfType(actual, GetType(ReadSubscriptionResponse), "instance type is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.UserIdAbsentOrIncorrect, actual.Status, "Status is incorrect")
            Assert.IsTrue(String.IsNullOrEmpty(actual.Comment), "Comment is not correct")


        End Sub
        <TestMethod()> _
        Public Sub ReadSubscription_Fail_Error_250()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = "b71d95d5fb963458"
            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale

            Dim actual As ReadSubscriptionResponse


            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            'Alle paramteter sollten anständig übergeben werden

            Expect.Once.On(webMock).Method("GetWebserviceResponse").With(New String() {"http://wbsapi.withings.net/notify?action=get&userid=29&publickey=b71d95d5fb963458&callbackurl=http%3a%2f%2fwww.yourdomain.net%2fyourCustomApplication.php&appli=1"}).Will( _
                                   [Return].Value(My.Resources.Error_250_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.ReadSubscription(userID, publicKey, callbackURL, application)
            mocks.VerifyAllExpectationsHaveBeenMet()

            Assert.IsInstanceOfType(actual, GetType(ReadSubscriptionResponse), "instance type is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.UserDataIsNotPublic, actual.Status, "Status is incorrect")
            Assert.IsTrue(String.IsNullOrEmpty(actual.Comment), "Comment is not correct")


        End Sub
        <TestMethod()> _
        Public Sub ReadSubscription_Fail_Error_286()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = "b71d95d5fb963458"
            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale

            Dim actual As ReadSubscriptionResponse


            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            'Alle paramteter sollten anständig übergeben werden

            Expect.Once.On(webMock).Method("GetWebserviceResponse").With(New String() {"http://wbsapi.withings.net/notify?action=get&userid=29&publickey=b71d95d5fb963458&callbackurl=http%3a%2f%2fwww.yourdomain.net%2fyourCustomApplication.php&appli=1"}).Will( _
                                   [Return].Value(My.Resources.Error_286_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.ReadSubscription(userID, publicKey, callbackURL, application)
            mocks.VerifyAllExpectationsHaveBeenMet()

            Assert.IsInstanceOfType(actual, GetType(ReadSubscriptionResponse), "instance type is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.NoSuchSubscriptionFound, actual.Status, "Status is incorrect")
            Assert.IsTrue(String.IsNullOrEmpty(actual.Comment), "Comment is not correct")


        End Sub
        <TestMethod()> _
        Public Sub ReadSubscription_Fail_Error_293()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = "b71d95d5fb963458"
            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale

            Dim actual As ReadSubscriptionResponse


            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            'Alle paramteter sollten anständig übergeben werden

            Expect.Once.On(webMock).Method("GetWebserviceResponse").With(New String() {"http://wbsapi.withings.net/notify?action=get&userid=29&publickey=b71d95d5fb963458&callbackurl=http%3a%2f%2fwww.yourdomain.net%2fyourCustomApplication.php&appli=1"}).Will( _
                                   [Return].Value(My.Resources.Error_293_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.ReadSubscription(userID, publicKey, callbackURL, application)
            mocks.VerifyAllExpectationsHaveBeenMet()

            Assert.IsInstanceOfType(actual, GetType(ReadSubscriptionResponse), "instance type is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.CallbackUrlIsAbsentOrIncorrect, actual.Status, "Status is incorrect")
            Assert.IsTrue(String.IsNullOrEmpty(actual.Comment), "Comment is not correct")


        End Sub
        <TestMethod()> _
        Public Sub ReadSubscription_Fail_Error_2555()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = "b71d95d5fb963458"
            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale

            Dim actual As ReadSubscriptionResponse


            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            'Alle paramteter sollten anständig übergeben werden

            Expect.Once.On(webMock).Method("GetWebserviceResponse").With(New String() {"http://wbsapi.withings.net/notify?action=get&userid=29&publickey=b71d95d5fb963458&callbackurl=http%3a%2f%2fwww.yourdomain.net%2fyourCustomApplication.php&appli=1"}).Will( _
                                   [Return].Value(My.Resources.Error_2555_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.ReadSubscription(userID, publicKey, callbackURL, application)
            mocks.VerifyAllExpectationsHaveBeenMet()

            Assert.IsInstanceOfType(actual, GetType(ReadSubscriptionResponse), "instance type is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.AnUnknownErrorOccured, actual.Status, "Status is incorrect")
            Assert.IsTrue(String.IsNullOrEmpty(actual.Comment), "Comment is not correct")


        End Sub


        <TestMethod()> _
        Public Sub CreateSubscription_Success()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = "b71d95d5fb963458"
            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim comment As String = "Your Own Application Description"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale

            Dim actual As SetSubscriptionResponse


            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            Expect.Once.On(webMock).Method("GetWebserviceResponse").With(New String() {"http://wbsapi.withings.net/notify?action=subscribe&userid=29&publickey=b71d95d5fb963458&callbackurl=http%3a%2f%2fwww.yourdomain.net%2fyourCustomApplication.php&appli=1&comment=Your%20Own%20Application%20Description"}).Will([Return].Value(My.Resources.probe_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.CreateSubscribtion(userID, publicKey, callbackURL, comment, application)
            mocks.VerifyAllExpectationsHaveBeenMet()

            Assert.IsTrue(actual.Success, "Success property is not correct")
            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.Successfull, actual.Status, "Status Property is not correct")

        End Sub
        <TestMethod()> _
        Public Sub CreateSubscription_Fail_Parameter_Validation()

            Dim target As WBSAPIConnector = New WBSAPIConnector

            'Assertation 1: Exception On Parameter UserID
            Try
                target.CreateSubscribtion(-1, Guid.NewGuid.ToString, "http://www.yourdomain.net/yourCustomApplication.php", _
                                          Guid.NewGuid.ToString, DeviceTypeEnum.BodyScale)
                Assert.Fail("ArgumentNullException for Parameter userId was not thrown")
            Catch ex As System.ArgumentNullException
                Assert.AreEqual(Of String)("userID", ex.ParamName, "User ID was not detected")
            Catch ex As Exception
                Assert.Fail("Wrong exception type was thrown on UserID check")
            End Try



            'Assertation 2: Exception On Parameter publicKey
            Try
                target.CreateSubscribtion(29, Nothing, "http://www.yourdomain.net/yourCustomApplication.php", _
                                          Guid.NewGuid.ToString, DeviceTypeEnum.BodyScale)
                Assert.Fail("ArgumentNullException for Parameter publicKey was not thrown")
            Catch ex As System.ArgumentNullException
                Assert.AreEqual(Of String)("publicKey", ex.ParamName, "publicKey was not detected")
            Catch ex As Exception
                Assert.Fail("Wrong exception type was thrown on publicKey check")
            End Try

            'Assertation 3: Exception On Parameter callbackURL
            Try
                target.CreateSubscribtion(29, Guid.NewGuid.ToString, Nothing, _
                                          Guid.NewGuid.ToString, DeviceTypeEnum.BodyScale)
                Assert.Fail("ArgumentNullException for Parameter callbackURL was not thrown")
            Catch ex As System.ArgumentNullException
                Assert.AreEqual(Of String)("callbackURL", ex.ParamName, "callbackURL was not detected")
            Catch ex As Exception
                Assert.Fail("Wrong exception type was thrown on callbackURL check")
            End Try

            Dim callbackURL As String = String.Empty
            For i As Integer = 0 To 135
                callbackURL += "a"
            Next

            'Assertation 4: Exception On Parameter callbackURL - maxLength
            Try
                target.CreateSubscribtion(29, Guid.NewGuid.ToString, callbackURL, _
                                          Guid.NewGuid.ToString, DeviceTypeEnum.BodyScale)
                Assert.Fail("ArgumentException for Parameter callbackURL was not thrown")
            Catch ex As System.ArgumentException
                Assert.AreEqual(Of String)("callbackURL", ex.ParamName, "callbackURL to long problem was not detected")
            Catch ex As Exception
                Assert.Fail("Wrong exception type was thrown on callbackURL-maxlength check")
            End Try


            'Assertation 5: Exception On Parameter comment
            Try
                target.CreateSubscribtion(29, Guid.NewGuid.ToString, "http://www.yourdomain.net/yourCustomApplication.php", _
                                         Nothing, DeviceTypeEnum.BodyScale)
                Assert.Fail("ArgumentNullException for Parameter comment was not thrown")
            Catch ex As System.ArgumentNullException
                Assert.AreEqual(Of String)("comment", ex.ParamName, "comment was not detected")
            Catch ex As Exception
                Assert.Fail("Wrong exception type was thrown on comment check")
            End Try

        End Sub
        <TestMethod()> _
        Public Sub CreateSubscription_Fail_Error_247()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale
            Dim comment As String = Guid.NewGuid.ToString
            Dim actual As SetSubscriptionResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)
            WBSAPIConnector.WebConnector = webMock

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_247_SampleResult))
            actual = target.CreateSubscribtion(userID, publicKey, callbackURL, comment, application)

            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.UserIdAbsentOrIncorrect, actual.Status, "Status Error")
            Assert.IsFalse(actual.Success, "Success should be false")

        End Sub
        <TestMethod()> _
        Public Sub CreateSubscription_Fail_Error_250()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale
            Dim comment As String = Guid.NewGuid.ToString
            Dim actual As SetSubscriptionResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)
            WBSAPIConnector.WebConnector = webMock

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_250_SampleResult))
            actual = target.CreateSubscribtion(userID, publicKey, callbackURL, comment, application)

            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.UserDataIsNotPublic, actual.Status, "Status Error")
            Assert.IsFalse(actual.Success, "Success should be false")

        End Sub
        <TestMethod()> _
        Public Sub CreateSubscription_Fail_Error_293()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale
            Dim comment As String = Guid.NewGuid.ToString
            Dim actual As SetSubscriptionResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)
            WBSAPIConnector.WebConnector = webMock

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_293_SampleResult))
            actual = target.CreateSubscribtion(userID, publicKey, callbackURL, comment, application)

            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.CallbackUrlIsAbsentOrIncorrect, actual.Status, "Status Error")
            Assert.IsFalse(actual.Success, "Success should be false")

        End Sub
        <TestMethod()> _
        Public Sub CreateSubscription_Fail_Error_304()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale
            Dim comment As String = Guid.NewGuid.ToString
            Dim actual As SetSubscriptionResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)
            WBSAPIConnector.WebConnector = webMock

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_304_SampleResult))
            actual = target.CreateSubscribtion(userID, publicKey, callbackURL, comment, application)

            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.CommentAbsentOrIncorrect, actual.Status, "Status Error")
            Assert.IsFalse(actual.Success, "Success should be false")

        End Sub
        <TestMethod()> _
        Public Sub CreateSubscription_Fail_Error_2555()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale
            Dim comment As String = Guid.NewGuid.ToString
            Dim actual As SetSubscriptionResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)
            WBSAPIConnector.WebConnector = webMock

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_2555_SampleResult))
            actual = target.CreateSubscribtion(userID, publicKey, callbackURL, comment, application)

            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.AnUnknownErrorOccured, actual.Status, "Status Error")
            Assert.IsFalse(actual.Success, "Success should be false")

        End Sub


        <TestMethod()> _
        Public Sub RevokeSubscription_Success()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = "b71d95d5fb963458"
            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale

            Dim actual As SetSubscriptionResponse


            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)

            'Alle paramteter sollten anständig übergeben werden

            Expect.Once.On(webMock).Method("GetWebserviceResponse").With(New String() {"http://wbsapi.withings.net/notify?action=revoke&userid=29&publickey=b71d95d5fb963458&callbackurl=http%3a%2f%2fwww.yourdomain.net%2fyourCustomApplication.php&appli=1"}).Will([Return].Value(My.Resources.probe_SampleResult))
            WBSAPIConnector.WebConnector = webMock

            actual = target.RevokeSubscription(userID, publicKey, callbackURL, application)
            mocks.VerifyAllExpectationsHaveBeenMet()

            Assert.IsTrue(actual.Success, "retval is not correct")


        End Sub
        <TestMethod()> _
        Public Sub RevokeSubscription_Fail_Parameter_Validation()

            Dim target As WBSAPIConnector = New WBSAPIConnector

            'Assertation 1: Exception On Parameter UserID
            Try
                target.RevokeSubscription(-1, Guid.NewGuid.ToString, "http://www.yourdomain.net/yourCustomApplication.php", _
                                          DeviceTypeEnum.BodyScale)
                Assert.Fail("ArgumentNullException for Parameter userId was not thrown")
            Catch ex As System.ArgumentNullException
                Assert.AreEqual(Of String)("userID", ex.ParamName, "User ID was not detected")
            Catch ex As Exception
                Assert.Fail("Wrong exception type was thrown on UserID check")
            End Try



            'Assertation 2: Exception On Parameter publicKey
            Try
                target.RevokeSubscription(29, Nothing, "http://www.yourdomain.net/yourCustomApplication.php", _
                                          DeviceTypeEnum.BodyScale)
                Assert.Fail("ArgumentNullException for Parameter publicKey was not thrown")
            Catch ex As System.ArgumentNullException
                Assert.AreEqual(Of String)("publicKey", ex.ParamName, "publicKey was not detected")
            Catch ex As Exception
                Assert.Fail("Wrong exception type was thrown on publicKey check")
            End Try

            'Assertation 3: Exception On Parameter callbackURL
            Try
                target.RevokeSubscription(29, Guid.NewGuid.ToString, Nothing, _
                                          DeviceTypeEnum.BodyScale)
                Assert.Fail("ArgumentNullException for Parameter callbackURL was not thrown")
            Catch ex As System.ArgumentNullException
                Assert.AreEqual(Of String)("callbackURL", ex.ParamName, "callbackURL was not detected")
            Catch ex As Exception
                Assert.Fail("Wrong exception type was thrown on callbackURL check")
            End Try

            Dim callbackURL As String = String.Empty
            For i As Integer = 0 To 135
                callbackURL += "a"
            Next

            'Assertation 4: Exception On Parameter callbackURL - maxLength
            Try
                target.RevokeSubscription(29, Guid.NewGuid.ToString, callbackURL, _
                                           DeviceTypeEnum.BodyScale)
                Assert.Fail("ArgumentException for Parameter callbackURL was not thrown")
            Catch ex As System.ArgumentException
                Assert.AreEqual(Of String)("callbackURL", ex.ParamName, "callbackURL to long problem was not detected")
            Catch ex As Exception
                Assert.Fail("Wrong exception type was thrown on callbackURL-maxlength check")
            End Try


        End Sub
        <TestMethod()> _
        Public Sub RevokeSubscription_Fail_Error_247()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale
            Dim actual As SetSubscriptionResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)
            WBSAPIConnector.WebConnector = webMock

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_247_SampleResult))
            actual = target.RevokeSubscription(userID, publicKey, callbackURL, application)

            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.UserIdAbsentOrIncorrect, actual.Status, "Status Error")
            Assert.IsFalse(actual.Success, "Success should be false")

        End Sub
        <TestMethod()> _
        Public Sub RevokeSubscription_Fail_Error_250()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale
            Dim actual As SetSubscriptionResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)
            WBSAPIConnector.WebConnector = webMock

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_250_SampleResult))
            actual = target.RevokeSubscription(userID, publicKey, callbackURL, application)

            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.UserDataIsNotPublic, actual.Status, "Status Error")
            Assert.IsFalse(actual.Success, "Success should be false")

        End Sub
        <TestMethod()> _
        Public Sub RevokeSubscription_Fail_Error_293()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale
            Dim actual As SetSubscriptionResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)
            WBSAPIConnector.WebConnector = webMock

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_293_SampleResult))
            actual = target.RevokeSubscription(userID, publicKey, callbackURL, application)

            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.CallbackUrlIsAbsentOrIncorrect, actual.Status, "Status Error")
            Assert.IsFalse(actual.Success, "Success should be false")

        End Sub
        <TestMethod()> _
        Public Sub RevokeSubscription_Fail_Error_294()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale
            Dim actual As SetSubscriptionResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)
            WBSAPIConnector.WebConnector = webMock

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_294_SampleResult))
            actual = target.RevokeSubscription(userID, publicKey, callbackURL, application)

            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.NoSubscriptionCouldBeDeleted, actual.Status, "Status Error")
            Assert.IsFalse(actual.Success, "Success should be false")

        End Sub
        <TestMethod()> _
        Public Sub RevokeSubscription_Fail_Error_2555()

            Dim target As WBSAPIConnector = New WBSAPIConnector
            Dim userID As Integer = 29
            Dim publicKey As String = Guid.NewGuid.ToString

            Dim callbackURL As String = "http://www.yourdomain.net/yourCustomApplication.php"
            Dim application As DeviceTypeEnum = DeviceTypeEnum.BodyScale
            Dim actual As SetSubscriptionResponse

            Dim mocks As NMock2.Mockery = New NMock2.Mockery()
            Dim webMock As IHttpConnector = Nothing

            webMock = CType(mocks.NewMock(GetType(IHttpConnector)), IHttpConnector)
            WBSAPIConnector.WebConnector = webMock

            Stub.On(webMock).Method("GetWebserviceResponse").Will([Return].Value(My.Resources.Error_2555_SampleResult))
            actual = target.RevokeSubscription(userID, publicKey, callbackURL, application)

            Assert.AreEqual(Of StatusResponseEnum)(StatusResponseEnum.AnUnknownErrorOccured, actual.Status, "Status Error")
            Assert.IsFalse(actual.Success, "Success should be false")

        End Sub



 
    End Class

End Namespace